<template>
  <base-breadcrumb>
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <a-card>
      <!-- <title-name title="危险源辨识会议及清单" /> -->
      <div class="table-operator">
        <a-button
          v-btnPermission="'hse_004_add_01'"
          type="primary"
          icon="plus"
          @click="handleUpdate('add', {})"
          v-if="hideBuquBtn()"
        >
          新增辨识会议
        </a-button>
      </div>
      <list-table
        ref="table"
        :columns="columns"
        :request="loadData"
      >
        <template slot="sort" slot-scope="text, record, index">{{ index + 1 }}</template>
        <template slot="speakerStr" slot-scope="text, record">
            {{record.speakerStr? record.speakerStr:record.speakerId}}
        </template>
        <template slot="actions" slot-scope="text, record">
          <MoreButton>
              <a v-btn-permission="'hse_004_loo_04'" @click="handleUpdate('look', record)">查看会议</a>
              <a
                v-btn-permission="'hse_004_edi_02'"
                v-if="record.status === STATUS.WAIT_START || record.status === STATUS.REJECT&&hideBuquBtn()"
                @click="handleUpdate('edit', record)"
              >编辑</a>
              <a
                v-btn-permission="'hse_004_del_03'"
                v-if="record.status === STATUS.WAIT_START || record.status === STATUS.STARTING || record.status === STATUS.REJECT || record.status === STATUS.END&&hideBuquBtn()"
                @click="handleUpdate('del', record)"
              >删除</a>
              <!--            <span @click="$router.push({name: 'safetyAddConferenceWaitDo',query: {id: record.id || '',  }})">待办</span>-->
              <a
                v-btn-permission="'hse_004_loo_04'"
                v-if="record.status === STATUS.SUBMITTING || record.status === STATUS.REJECT || record.status === STATUS.END"
              >
              <approval-button :id="record.id" /></a>
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>
<script>
import MoreButton from '@/components/MoreButton'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import listStatus from '@/components/list_status/meeting_status'
import Api from '@/api/office/hazardIdentification'

let STATUS = {
  DRAFT: 0,
  WAIT_START: 1,
  STARTING: 2,
  SUBMITTING: 3,
  REJECT: 4,
  END: 5
}
export default {
  name: 'a' + Date.now(),
  components: {
    listStatus,
    MoreButton
  },
  data() {
    return {
      STATUS,
      columns: [
        {
          title: '序号',
          dataIndex: 'sort',
          scopedSlots: { customRender: 'sort' },
          width: 70
        },
        {
          title: '所属分公司',
          dataIndex: 'branchComName',
          width: 120
        },
        {
          title: '所属项目',
          dataIndex: 'projectName',
          width: 150
        },
        {
          title: '会议名称',
          dataIndex: 'meetingName',
          width: 150
        },
        {
          title: '会议月份',
          dataIndex: 'month',
          width: 120
        },
        {
          title: '参会人数',
          dataIndex: 'shouldNum',
          width: 120
        },
        {
          title: '主持人',
          dataIndex: 'speakerStr',
          width: 130,
         scopedSlots: { customRender: 'speakerStr' }
        },
        {
          title: '召开时间',
          dataIndex: 'meetTime',
          width: 150
        },
        {
          title: '状态',
          dataIndex: 'statusStr',
          width: 100
        },
        {
          title: '操作',
          dataIndex: 'actions',
          width: 220,
          fixed: 'right',
          scopedSlots: { customRender: 'actions' }
        }
      ],
      searchArr: [
        // {
        //   name: '所属分公司',
        //   valueKey: 'branchComId',
        //   type: SelectSubCompany
        // },
        {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
        // {
        //   name: '所属项目',
        //   keyValue: 'branchComId',
        //   valueKey: 'projectId',
        //   type: SelectProject
        // },
        {
          name: '召开时间',
          value: 'meetTime',
          type: 'dateRangeFormat'
        },
        {
          name: '会议月份',
          value: 'month',
          type: 'month'
        },
        {
          name: '状态',
          value: 'status',
          type: 'select',
          data: [
            { value: 1, label: '待开始' },
            { value: 2, label: '进行中' },
            { value: 3, label: '审核中' },
            { value: 5, label: '已完结' },
            { value: 4, label: '审核不通过' }
          ]
        }
      ],
      queryParam: {},
      loadData: (q) => Api.findListByMain(Object.assign(q, { query: this.queryParam }))
    }
  },
  methods: {
    //搜索
    search(val = {}) {
      this.queryParam = val
      this.$refs.table.refresh(true)
    },

    // 处理更新操作（新增、编辑）
    async handleUpdate(type, data = {}) {
      if (type === 'del') {
        this.$delList2(Api.deleteByMain, this.$refs.table.refresh, { ids: [data.id] },
          null,
          null,
          `你正在删除(会议名称）${data.meetingName}，将连同关联的数据一起删除，确认删除吗？`
        )
      } else {
        this.$router.push({
          name: 'safetyAddConference',
          query: {
            id: data.id || '',
            pageType: type
          }
        })
      }
    }
  }
}
</script>
